package com.train.implementRunnable;

import java.lang.Thread.State;
/**
 * 实现{@link Runnable}接口中的{@link Runnable#run()}方法，
 * 并将类实体交给{@link Thread#Thread(Runnable)}代理，并以{@link Thread#start()}执行
 * */
public class ImplementRunnable implements Runnable{
    public static Integer count = 0;
    /**
     * 实现{@link Runnable#run()}方法
     * */
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(100);
                String threadName = Thread.currentThread().getThreadGroup().getName();
                State threadStatus = Thread.currentThread().getState();
                System.out.println(threadName+":"+ Thread.currentThread().getName()+" is running! count:"+ (count++)+" status:"+threadStatus);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
